require(localValue >= 100, “Value should be either 100 or

more”);

someValue = localValue;

}

function retrieveValue() public view returns (uint) {

return someValue;

}

}

2.5.18.2 Revert

The revert function is another way to trigger the exceptions from

within the other code blocks to flag an error and revert the current

call. The function aborts the execution and reverts any changes

done to the state. It’s especially useful before running any complex

logical flow.

The function takes an optional string message containing the details

about the error that is passed back to the caller.

The following example shows how to use an error string together

with revert:

// SPDX-License-Identifier: SOME IDENTIFIER

pragma solidity ^0.8.10;

contract RevertFunctionTest {

uint someValue;

function testRevert(uint localValue) public {

if (localValue >= 100) {

revert(“Value too high”);

}

someValue = localValue;

}

function retrieveValue() public view returns (uint) {

return someValue;

}

}